package Client.GUI;

import java.util.ArrayList;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import Server.DataBase.Student;
import Server.DataBase.Teacher;

public class StudentTableModel extends AbstractTableModel {

  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	Vector<String[]> cache; // will hold String[] objects . . .

	int colCount=3;

	String[] headers = {"ID", "Last Name", "First Name"};

	public StudentTableModel() {
		cache = new Vector<String[]>();
	}

	public String getColumnName(int i) {
		return headers[i];
	}

	public int getColumnCount() {
		return colCount;
	}

	public int getRowCount() {
		return cache.size();
	}

	public Object getValueAt(int row, int col) {
		return ((String[]) cache.elementAt(row))[col];
	}
  
	public void setValueAt(int row, int col, String msg){
	  ((String[]) cache.elementAt(row))[col] = msg;
	  fireTableChanged(null);
  }
  
  public void setArray(ArrayList<Student> array){
	  cache.removeAllElements();
	  for (int i=0; i<array.size(); i++) addToArray(array.get(i));
	  fireTableChanged(null);
  }
  
  public void addToArray(Student student){
	  String[] record = new String[colCount];
	  record[0] = Integer.toString(student.getIdUser());
	  record[1] = student.getLastName();
	  record[2] = student.getFirstName();
	  cache.addElement(record);
  }
  
  public void setArrayT(ArrayList<Teacher> array){
	  cache.removeAllElements();
	  for (int i=0; i<array.size(); i++) addToArrayT(array.get(i));
	  fireTableChanged(null);
  }
  
  public void addToArrayT(Teacher t){
	  String[] record = new String[colCount];
	  record[0] = Integer.toString(t.getIdUser());
	  record[1] = t.getLastName();
	  record[2] = t.getFirstName();
	  cache.addElement(record);
  }
}